﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace MvcHeatloss.Models
{
    [MetadataType(typeof(SkylightData))]
    public partial class Skylight
    {
         public ProjectEntities db = new ProjectEntities();
        
        public Skylight(double length, double width, string type, string temp)
        {
            SkylightArea = CalcHeatoss.CalcArea(length , width);
            SkylightType = type;
            SkylightUValue = (double)db.UValues.Where(d => d.Description == type).Select(u => u.UValue1).First();
            SkylightTemp = Int32.Parse(temp);
            SkylightHeatloss = CalcHeatoss.FabricHeatloss(this.SkylightUValue, this.SkylightArea, this.SkylightTemp);
        }
        public Skylight(): base()
        {
        }

        public string SkylightType { get; set; }

        public int SkylightTemp { get; set; }

        public double SkylightUValue { get; set; }

        public double SkylightArea { get; set; }

        double skylightHeatloss;
        public double SkylightHeatloss 
        {
            get
            {
                return skylightHeatloss;
            }
            set
            {
                skylightHeatloss = CalcHeatoss.FabricHeatloss(this.SkylightUValue, this.SkylightArea, this.SkylightTemp);
            }
        }
    }
    public class SkylightData
    {
        [Required(ErrorMessage = "You must enter a Skylight Length")]
        [Display(Name = "Skylight Length")]
        public decimal Length { get; set; }

        [Required(ErrorMessage = "You must enter a Skylight Width")]
        [Display(Name = "Skylight Width")]
        public decimal Width { get; set; }

    }
}